package com.base.lib.base

import android.content.Context
import com.google.gson.Gson
import java.lang.ref.Reference
import java.lang.ref.WeakReference

abstract class BasePresenter<T> {
    protected var mViewRef: Reference<T?>? = null
    protected var mContext: Context? = null
    protected var mGson = Gson()
//    protected var mSpHelper: SpHelper? = null
    fun attachView(view: T) {
        mViewRef = WeakReference(view)
    }

    protected val view: T?
        protected get() = mViewRef!!.get()

    val isViewAttached: Boolean
        get() = mViewRef != null && mViewRef!!.get() != null

    fun detachView() {
        if (mViewRef != null) {
            mViewRef!!.clear()
            mViewRef = null
        }
    }

    abstract fun cancelCall()
}